#ifndef UWBWIDGET_H
#define UWBWIDGET_H

#include <QPushButton>
#include "qrviz.hpp"
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include "QVTKOpenGLNativeWidget.h"
#include <QTableWidget>
#include <QStyledItemDelegate>
#include <pcl/io/pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp>
#include <vtkPointPicker.h>
#include <QComboBox>
#include <QLineEdit>
#include <vtkCaptionWidget.h>
#include <vtkCaptionRepresentation.h>

typedef pcl::PointXYZI PointT;
typedef pcl::PointCloud<PointT> PointCloudT;

class HoveredRowItemDelegate : public QStyledItemDelegate
{
public:
    explicit HoveredRowItemDelegate(QTableWidget *parent = nullptr);

protected:
    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;

private:
    const QTableWidget *tableWidget{};
};

class NumericComboBox : public QComboBox
{
    Q_OBJECT
public:
    NumericComboBox(QWidget *parent = nullptr) : QComboBox(parent)
    {
        // 确保QComboBox是可编辑的
        setEditable(true);
        // 获取lineEdit
        QLineEdit *lineEdit = new QLineEdit();
        if (lineEdit) {
            // 创建整数验证器，范围可以根据需要调整
            QIntValidator *validator = new QIntValidator(this);
            lineEdit->setValidator(validator);
        }
    }
};


class QToolBar;
class UWBWidget :public QWidget
{
    Q_OBJECT
public:
    explicit UWBWidget(QWidget *parent = nullptr);
    QVTKOpenGLNativeWidget *getVtkWidget();
    vtkCaptionWidget *getCaptionWidget();
    vtkCaptionRepresentation* getCaptionRepresentation();



signals:
    void addSelectPoint(double pos[3]);


public slots:
    void onOpenPCD();
    void onPointSelect(QMouseEvent *event);
    void onPclPointSize(QString size);
    void onResetCamera();
    void onFreshSelectPoint(double pos[3]);

protected:
     bool eventFilter(QObject *object, QEvent *event);

private:
    void setupUI();
    void setToolBar();
    void showSelectPoint();
    void freshVtk();
    void updateBaseStationSelection(); // 添加基站选择状态更新函数
    void showCoordinateOrigin(); // 添加显示坐标原点功能


private:
    void pointpicking();


private:

    QRviz * m_rviz;
    QPushButton *m_btnOpenPcd;

    QToolBar *m_toolBar;

    QTableWidget *m_table;

    NumericComboBox* m_combox;

    int m_selectedBaseStation; // 添加选中的基站索引

    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
    QVTKOpenGLNativeWidget *m_vtkWidget = nullptr;
    //vtkSmartPointer<vtkRenderer> renderer;
    vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow;
    vtkNew<vtkPointPicker> picker;
    vtkNew<vtkCaptionWidget> m_captionWidget;
    vtkNew<vtkCaptionRepresentation> m_captionRepresentation;
};
#endif // UWBWIDGET_H
















//#ifndef UWBWIDGET_H
//#define UWBWIDGET_H

//#include <QPushButton>
//#include "qrviz.hpp"
//#include <pcl/io/pcd_io.h>
//#include <pcl/visualization/pcl_visualizer.h>
//#include "QVTKOpenGLNativeWidget.h"
//#include <QTableWidget>
//#include <QStyledItemDelegate>
//#include <pcl/io/pcd_io.h>
//#include <pcl/point_cloud.h>
//#include <pcl/point_types.h>
//#include <pcl/visualization/pcl_visualizer.h>
//#include <boost/thread/thread.hpp>
//#include <vtkPointPicker.h>
//#include <QComboBox>
//#include <QLineEdit>
//#include <vtkCaptionWidget.h>
//#include <vtkCaptionRepresentation.h>

//typedef pcl::PointXYZI PointT;
//typedef pcl::PointCloud<PointT> PointCloudT;

//class HoveredRowItemDelegate : public QStyledItemDelegate
//{
//public:
//    explicit HoveredRowItemDelegate(QTableWidget *parent = nullptr);

//protected:
//    void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;

//private:
//    const QTableWidget *tableWidget{};
//};

//class NumericComboBox : public QComboBox
//{
//    Q_OBJECT
//public:
//    NumericComboBox(QWidget *parent = nullptr) : QComboBox(parent)
//    {
//        // 确保QComboBox是可编辑的
//        setEditable(true);
//        // 获取lineEdit
//        QLineEdit *lineEdit = new QLineEdit();
//        if (lineEdit) {
//            // 创建整数验证器，范围可以根据需要调整
//            QIntValidator *validator = new QIntValidator(this);
//            lineEdit->setValidator(validator);
//        }
//    }
//};


//class QToolBar;
//class UWBWidget :public QWidget
//{
//    Q_OBJECT
//public:
//    explicit UWBWidget(QWidget *parent = nullptr);
//    QVTKOpenGLNativeWidget *getVtkWidget();
//    vtkCaptionWidget *getCaptionWidget();
//    vtkCaptionRepresentation* getCaptionRepresentation();



//signals:
//    void addSelectPoint(double pos[3]);


//public slots:
//    void onOpenPCD();
//    void onPointSelect(QMouseEvent *event);
//    void onPclPointSize(QString size);
//    void onResetCamera();
//    void onFreshSelectPoint(double pos[3]);

//protected:
//     bool eventFilter(QObject *object, QEvent *event);

//private:
//    void setupUI();
//    void setToolBar();
//    void showSelectPoint();
//    void freshVtk();



//private:
//    void pointpicking();


//private:

//    QRviz * m_rviz;
//    QPushButton *m_btnOpenPcd;

//    QToolBar *m_toolBar;

//    QTableWidget *m_table;

//    NumericComboBox* m_combox;



//    boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
//    QVTKOpenGLNativeWidget *m_vtkWidget = nullptr;
//    //vtkSmartPointer<vtkRenderer> renderer;
//    vtkSmartPointer<vtkGenericOpenGLRenderWindow> renderWindow;
//    vtkNew<vtkPointPicker> picker;
//    vtkNew<vtkCaptionWidget> m_captionWidget;
//    vtkNew<vtkCaptionRepresentation> m_captionRepresentation;
//};
//#endif // UWBWIDGET_H
